package demoMod.invincibleOne.patches;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.saveAndContinue.SaveFile;
import demoMod.invincibleOne.InvincibleOneMod;

public class CardCrawlGamePatch {
    @SpirePatch(
            clz = CardCrawlGame.class,
            method = "getDungeon",
            paramtypez = {
                    String.class,
                    AbstractPlayer.class
            }
    )
    @SpirePatch(
            clz = CardCrawlGame.class,
            method = "getDungeon",
            paramtypez = {
                    String.class,
                    AbstractPlayer.class,
                    SaveFile.class
            }
    )
    public static class PatchGetDungeon {
        public static void Prefix(CardCrawlGame game) {
            InvincibleOneMod.addToBot(new AbstractGameAction() {
                @Override
                public void update() {
                    if (AbstractDungeon.actNum == 2) {
                        if (InvincibleOneMod.seriousLevel[CardCrawlGame.saveSlot] >= 3) {
                            ReflectionHacks.setPrivateStatic(AbstractDungeon.class, "cardUpgradedChance", 0.125F);
                        } else {
                            ReflectionHacks.setPrivateStatic(AbstractDungeon.class, "cardUpgradedChance", 0.25F);
                        }
                    } else if (AbstractDungeon.actNum >= 3) {
                        if (InvincibleOneMod.seriousLevel[CardCrawlGame.saveSlot] >= 3) {
                            ReflectionHacks.setPrivateStatic(AbstractDungeon.class, "cardUpgradedChance", 0.25F);
                        } else {
                            ReflectionHacks.setPrivateStatic(AbstractDungeon.class, "cardUpgradedChance", 0.5F);
                        }
                    }
                    isDone = true;
                }
            });
        }
    }
}
